import QtQuick 1.1
import VPlay 1.0
import Box2D 1.0 // needed for Body.Static
import "../."
import "../particles"

EntityBase {
  entityType: "roost"

  poolingEnabled: true

  // put them before the windows
  z:1

  Component.onCompleted: console.debug("Roost.onCompleted()")
  Component.onDestruction: console.debug("Roost.onDestruction()")

  Image {
    id: sprite
    source: "../img/chicken-dead02.png"

    width: 32
    height: 32

    anchors.centerIn: parent
  }

  BoxCollider {
    id: collider
    bodyType: Body.Static

    anchors.fill: sprite
    //        anchors.centerIn: parent
    //        width: gridSize
    //        height: gridSize

    fixture.onBeginContact: {
        // play the collision sound when the box collides with anything, but not if the sound is already playing
        //if(scene.collisionSoundsEnabled && !collisionSound.playing)
        //    collisionSound.play();

        //if(scene.particlesEnabled)
        var fixture = other;
        var body = fixture.parent;
        var component = body.parent;
        var collidedEntity = component.owningEntity;
        var collidedEntityType = collidedEntity.entityType;
        if(collidedEntityType === "rocket") {
            // the coin is pooled for better performance
            collidedEntity.removeEntity();
            removeEntity();
        }
        else if(collidedEntityType === "player") {
            collisionParticleEffect.start();
        }
    }

//    fixture.onEndContact:
//    {

//        var fixture = other;
//        var body = fixture.parent;
//        var component = body.parent;
//        var collidedEntity = component.owningEntity;
//        var collidedEntityType = collidedEntity.entityType;
//        if(collidedEntityType === "player") {
//            collisionParticleEffect.stop();
//            collisionParticleEffect.stopLivingParticles();
//        }
//    }
  }

  FireParticles
  {
    id: collisionParticleEffect
  }

}
